package com.efounder.news.adapter;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import com.efounder.news.bean.MultiLangChannelListBean;
import com.efounder.news.fragment.NewsListFragment;
import com.efounder.news.http.Api;

import java.util.List;

/**
 * Created by slp on 2018/2/7.
 */

public class ListFragmentAdapter extends FragmentStatePagerAdapter {

    private List<MultiLangChannelListBean> mChannelList;

    public ListFragmentAdapter(FragmentManager fm,List<MultiLangChannelListBean> channels) {
        super(fm);
        this.mChannelList = channels;
    }

    @Override
    public Fragment getItem(int position) {
        MultiLangChannelListBean channel = mChannelList.get(position);
        NewsListFragment    mNewsListFragment = NewsListFragment.newInstance(new Api().isChineseNews() ?
                channel.getChannelId() : channel.getEnChannelId());
        return mNewsListFragment;
    }

    @Override
    public int getCount() {
        return new Api().isChineseNews() ? mChannelList.size() : mChannelList.size() - 1;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return new Api().isChineseNews() ? mChannelList.get(position).getChannelName() :
                mChannelList.get(position).getEnChannelName();
    }
}
